<?php

namespace App;


use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class Chest extends Authenticatable
{
    use Notifiable;
    public $table = "chest";
    use Notifiable;

    const COMPANY = 1;
    const USER =2;
    const TIME = 3;
    const BUYER = 4;

    public static $roles = [
        self::USER => '个人租赁',
        self::COMPANY => '企业租赁',
        self::TIME => '时租用户',
        self::BUYER => '企业采购',
    ];
    public static $blades = [
        self::USER => 'default',
        self::COMPANY => 'company',
        self::TIME => 'time',
        self::BUYER => 'company',
    ];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'chest_number', 'chest_name',
    ];
    public function isRole($role = 0)
    {
        return $role == $this->type_id;
    }
    public function isTime()
    {
        return $this->isRole(self::TIME);
    }

    public function isUser()
    {
        return $this->isRole(self::USER);
    }

    public function isCompany()
    {
        return $this->isRole(self::COMPANY);
    }

    public function isBuyer()
    {
        return $this->isRole(self::BUYER);
    }

    public function getRole()
    {
        return array_get(self::$roles, $this->type_id);
    }
    public function getBlade()
    {

        $slug = array_get(self::$blades, $this->type_id);
        return 'user.partial.' . $slug;
    }

    //获取柜子信息
    public static function getSelectOptions()
    {
        $options = self::pluck('chest_number', 'id');
        return $options;
    }
    public function branches()
    {
        return $this->hasOne(Branches::class, 'id', 'branches_id');
    }

    public function chest()
    {
        return $this->belongsTo(ChestType::class, 'type_id');
    }
    public function type()
{
    return $this->hasOne(ChestType::class, 'id');
}

    public function getAddress()
    {
        return $this->address;
    }

    public function getNumber()
    {
        return $this->chest_number;
    }

    public function grip()
    {
        return $this->hasMany(Grid::class, 'id', 'Chest_id');
    }


    public function agent()
    {
        return $this->belongsTo(User::class, 'agent_id', 'id');
    }
    public function inv()
    {
        return $this->belongsTo(User::class, 'invesor_id', 'id');
    }
    public function partner()
    {
        return $this->belongsTo(User::class, 'parteny_id', 'id');
    }



}
